package com.xjk.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xjk.bean.FcBuilding;
import com.xjk.bean.FcEstate;
import com.xjk.bean.TblCompany;
import com.xjk.mapper.FcBuildingMapper;
import com.xjk.mapper.FcEstateMapper;
import com.xjk.mapper.TblCompanyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @author Xjk
 */

@Service
public class EstateService {

    @Autowired
    private TblCompanyMapper tblCompanyMapper;

    @Autowired
    private FcEstateMapper fcEstateMapper;

    @Autowired
    private FcBuildingMapper fcBuildingMapper;

    public List<TblCompany> selectCompanies(){
        System.out.println(tblCompanyMapper.selectCompany());
        return tblCompanyMapper.selectCompany();
    }

    public Integer insertEstate(FcEstate fcEstate) {
        QueryWrapper<FcEstate> queryWrapper = new QueryWrapper<FcEstate>();
        queryWrapper.eq("estateCode",fcEstate.getEstateCode());
        System.out.println(fcEstate.getEstateCode());
        FcEstate result = fcEstateMapper.selectOne(queryWrapper);
        if(result==null){
            return fcEstateMapper.insert(fcEstate);
        }else {
            return 0;
        }

    }

    public List<FcBuilding> selectBuilding(Integer buildingNum, String estateCode) {

        List<FcBuilding> fcBuildings = new ArrayList<>();
        for (int i = 0; i < buildingNum; i++) {
            FcBuilding fcBuilding = new FcBuilding();
            fcBuilding.setBuildingCode("B-"+(i+1));
            fcBuilding.setBuildingName("第"+(i+1)+"号楼");
            fcBuilding.setEstateCode(estateCode);
            fcBuildingMapper.insert(fcBuilding);
            fcBuildings.add(fcBuilding);
        }
        return fcBuildings;
    }
}
